#include <qset.h>
#include "DynTargetItemSetPrivate.h"
#include "DynTargetItemPrivate.h"

DynTargetItemSetPrivate::DynTargetItemSetPrivate(const QString& name,DynTargetManagerPrivate* mgrPrivate):
mgr(mgrPrivate),
setName(name)
{
}

DynTargetItemSetPrivate::~DynTargetItemSetPrivate()
{
}

bool DynTargetItemSetPrivate::addDynTargetItem(DynTargetItem* item)
{
	if(!item || item->getDynTargetSet() != this)
		return false;

	if(!targetItems.contains(item))
		targetItems.append(item);
	return true;
}

DynTargetItem* DynTargetItemSetPrivate::createDynTargetItem(const QString& group,const QString& name,const QString& nation,const QString& target)
{
	auto item = new DynTargetItemPrivate(name,group,nation,target,this);
	targetItems.append(item);
	return item;
}

DynTargetItem* DynTargetItemSetPrivate::getDynTargetItemByName(const QString& name) const
{
	foreach(auto item,targetItems)
	{
		if(item->getName() == name)
			return item;
	}
	return nullptr;
}

DynTargetItem* DynTargetItemSetPrivate::getDynTargetItem(const QString& id) const
{
	foreach(auto item,targetItems)
	{
		if(item->getUid() == id)
			return item;
	}
	return nullptr;
}

QList<DynTargetItem*> DynTargetItemSetPrivate::getDynTargetListByGroup(const QString& group)
{
	QList<DynTargetItem*> list;
	foreach(auto item,targetItems)
	{
		if(item->getGroupName() == group)
			list << item;
	}
	return list;
}

DynTargetItem* DynTargetItemSetPrivate::getDynTargetItemByIndex(int index)
{
	if(targetItems.size() <= index)
		return nullptr;
	return targetItems.at(index);
}

int DynTargetItemSetPrivate::getDynTargetCount() const
{
	return targetItems.size();
}

bool DynTargetItemSetPrivate::removeDynTargetItem(DynTargetItem* item)
{
	if(!item)
		return false;
	return targetItems.removeOne(item);
}

void DynTargetItemSetPrivate::clearTargets()
{
	qDeleteAll(targetItems);
	targetItems.clear();
}

QList<DynTargetItem*> DynTargetItemSetPrivate::isDynTargetItemEx(int x,int y)
{
	return QList<DynTargetItem*>();
}

DynTargetItem* DynTargetItemSetPrivate::isTrackPoint(int x,int y,int* index)
{
	return nullptr;
}

void DynTargetItemSetPrivate::setGroupVisible(const QString& group,bool visible)
{
    
}

bool DynTargetItemSetPrivate::getGroupVisible(const QString& group)
{
	return false;
}
	
bool DynTargetItemSetPrivate::removeGroup(const QString& group)
{
	return false;
}
	
QStringList DynTargetItemSetPrivate::getAllGroups()
{
	QSet<QString> list;
	foreach(auto item,targetItems)
		list.insert(item->getGroupName());
	return list.toList();
}